#include <iostream>
#include <vector>

using namespace std;
class Solution
{
public:
    int daysBetweenDates(string date1, string date2)
    {
        auto get = [](string date) -> int
        {
            int m_days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
            auto isleap = [](int year) -> bool
            {
                return year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
            };
            int year, month, day;
            sscanf(date.c_str(), "%d-%d-%d", &year, &month, &day);

            int days = 0;
            for (int i = 1971; i < year; i++)
            {
                days += 365 + isleap(i);
            }

            for (int i = 1; i < month; i++)
            {
                days += (i == 2) ? (28 + isleap(year)) : m_days[i];
            }

            return days + day;
        };
        return abs(get(date1) - get(date2));
    }
};
int main()
{
    Solution s;
    string date1 = "2020-01-15", date2 = "2019-12-31";
    cout << s.daysBetweenDates(date1, date2) << endl;
    system("pause");
    return 0;
}
